import { Config } from "../../Config"
import { BigEvolution, BigState } from "../core/Big"
import { Player } from "../core/Player"
import GameUtils from "../GameUtils"
import Utils from "../GameUtils"
import { BaseHandler } from "./BaseHandler"

export class 精灵Handler extends BaseHandler{

    move(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_BIG_MOVE)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_start = startPoint.big
        big_start.actionOnce()
        let big_end = endPoint.big
        if(big_end != null) {
            big_end.deleteState(BigState.HIDE)
            big_start.die(player,endPoint.id)
            return
        }
        startPoint.big = null
        endPoint.big = big_start
        big_start.point = endPoint
        this.gameMgr.sendBroadcast(Utils.getObj("big_move",{"start":data.start,"end":data.end}))
        big_start.terrainAdapt()
    }


    精灵_赐福(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_精灵_赐福)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_end = endPoint.big
        big_end.addState(BigState.SHIELD)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let big_start = startPoint.big
        big_start.actionOnce()
        this.gameMgr.sendBroadcast(GameUtils.getObj("play_sound",{"sound":"精灵_祝福","username":big_start.player.username}))
    }


    精灵_庇护(data:any,player:Player) {
        this.handlerMgr.spendAction(player,Config.COST_精灵_庇护)
        let startPoint = this.gameMgr.map_point.get(data.start)
        let endPoint = this.gameMgr.map_point.get(data.end)
        let big_start = startPoint.big
        let big_end = endPoint.big
        big_end.addState(BigState.HIDE)
        this.gameMgr.sendBroadcast(GameUtils.getObj("play_sound",{"sound":"精灵_祝福","username":big_start.player.username}))
    }
}